//
//  WDGoutReviewVehicleServiceInfoView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2025/3/27.
//

#import "WDGoutReviewVehicleServiceInfoView.h"
#import "WDArrivalServiceDetailModel.h"
#import "WDWorderOrdMainVehSingleImageView.h"
#import "WDWorderOrdMainVehOtherImageVideoView.h" // 其它
#import "HZPhotoBrowser.h"

@interface WDGoutReviewVehicleServiceInfoView ()
@property (nonatomic, strong) WDArrivalServiceDetailModel *taskDetailModel;

/// 预约时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *appointTimeView;

/// 抢单时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *robOrderTimeView;

/// 抢单账号
@property (nonatomic, strong) WDTaskDetailBasicSingleView *robOrderAccountView;

/// 接车时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *meetCarTimeView;

/// 扫码位置
@property (nonatomic, strong) WDTaskDetailBasicSingleView *scanLocationView;

/// 扫码账户
@property (nonatomic, strong) WDTaskDetailBasicSingleView *scanAccountView;


@end

@implementation WDGoutReviewVehicleServiceInfoView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor whiteColor];
}

/// 预约时间
- (void)initWithAppointTimeView {
    if (!_appointTimeView) {
        CGRect frame = CGRectMake(0, 0, self.width, kWDTaskDetailBasicSingleViewHeight);
        _appointTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_appointTimeView];
    }
    if (self.taskDetailModel) {
        NSString *str = objectNull(self.taskDetailModel.appointmentTime);
        if ([str isEqualToString:@""]) {
            str = objectNull(self.taskDetailModel.createTime);
        }
        [_appointTimeView updateWithViewTitle:@"预约时间" value:str valueHeight:18];
    }
}

/// 抢单时间
- (void)initWithRobOrderTimeView {
    if (!_robOrderTimeView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.appointTimeView.bottom;
        _robOrderTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_robOrderTimeView];
    }
    if (self.taskDetailModel) {
        [_robOrderTimeView updateWithViewTitle:@"抢单时间" value:self.taskDetailModel.asignTime valueHeight:18];
    }
}

/// 抢单账号
- (void)initWithRobOrderAccountView {
    if (!_robOrderAccountView) {
        CGRect frame = self.robOrderTimeView.frame;
        frame.origin.y = self.robOrderTimeView.bottom;
        _robOrderAccountView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_robOrderAccountView];
    }
    if (self.taskDetailModel) {
        WDTaskFlowModel *flowModel = self.taskDetailModel.taskFlowList.firstObject;
        [_robOrderAccountView updateWithViewTitle:@"抢单账号" value:objectNull(flowModel.engineerName) valueHeight:18];
    }
}

/// 接车时间
- (void)initWithMeetCarTimeView {
    if (!_meetCarTimeView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.robOrderAccountView.bottom;
        _meetCarTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_meetCarTimeView];
    }
    if (self.taskDetailModel) {
        [_meetCarTimeView updateWithViewTitle:@"接车时间" value:self.taskDetailModel.receiveTime valueHeight:18];
    }
}

/// 扫码位置
- (void)initWithScanLocationView {
    WDTaskFlowModel *model = self.taskDetailModel.taskFlowList.firstObject;
    if (self.taskDetailModel.taskFlowList.count >= 2) {
        model = [self.taskDetailModel.taskFlowList objectOrNilAtIndex:1];
    }
    if (!_scanLocationView) {
        CGRect frame = self.appointTimeView.frame;
        frame.size.height = kWDTaskDetailBasicSingleViewHeight - 18 + model.scanAddressHeight;
        frame.origin.y = self.meetCarTimeView.bottom;
        _scanLocationView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
//        _scanLocationView.backgroundColor = [UIColor redColor];
        [self addSubview:_scanLocationView];
    }
    if (self.taskDetailModel) {
        
        [_scanLocationView updateWithViewTitle:@"扫码位置" value:model.scanAddress valueHeight:model.scanAddressHeight];
    }
}

/// 扫码账户
- (void)initWithScanAccountView {
    if (!_scanAccountView) {
        CGRect frame = self.appointTimeView.frame;
        frame.origin.y = self.scanLocationView.bottom;
        _scanAccountView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_scanAccountView];
    }
    if (self.taskDetailModel) {
        WDTaskFlowModel *model = self.taskDetailModel.taskFlowList.firstObject;
        if (self.taskDetailModel.taskFlowList.count >= 2) {
            model = [self.taskDetailModel.taskFlowList objectOrNilAtIndex:1];
        }
        [_scanAccountView updateWithViewTitle:@"扫码账户" value:model.engineerName valueHeight:18];
    }
}

- (void)updateWithViewData:(id)data {
    self.taskDetailModel = data;
    
    /// 预约时间
    [self initWithAppointTimeView];
    
    // 抢单时间
    [self initWithRobOrderTimeView];
    
    // 抢单账号
    [self initWithRobOrderAccountView];

    /// 接车时间
    [self initWithMeetCarTimeView];

    /// 扫码位置
    [self initWithScanLocationView];

    /// 扫码账户
    [self initWithScanAccountView];
}

@end
